package com.example.barcodeapp.ui.wode.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.fragment.app.FragmentManager;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.barcodeapp.R;
import com.example.barcodeapp.adapter.XiangQingZhiBoKe;
import com.example.barcodeapp.base.BaseAdapter;
import com.example.barcodeapp.common.Constants;
import com.example.barcodeapp.ui.wode.bean.DingDanBean;

import java.util.ArrayList;
import java.util.List;

public class HomeAdapter4 extends RecyclerView.Adapter<HomeAdapter4.ViewHolder> {
    private Context context;
    private List<DingDanBean.DataBean> dataBean;

    public HomeAdapter4(Context context, List<DingDanBean.DataBean> dataBean) {
        this.context = context;
        this.dataBean = dataBean;
    }

    @NonNull
    @Override
    public HomeAdapter4.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.adapter_item_home, parent, false);
        return new ViewHolder(inflate);
    }

    @Override
    public void onBindViewHolder(@NonNull HomeAdapter4.ViewHolder holder, int position) {
        Glide.with(context).load(Constants.Base_TPUrl + dataBean.get(position).getFengmian()).into(holder.mIvImg);
        holder.mTvTitleHome.setText(dataBean.get(position).getName());
        holder.mTvInTroduce.setText(dataBean.get(position).getDesc());
        holder.mTvIntroduction.setText("讲师：" + dataBean.get(position).getJiangshi());
        holder.mTvPriceHome.setText("¥" + dataBean.get(position).getPrice());
        holder.mTvCless.setText(dataBean.get(position).getKeshi() + "课");
        int state = dataBean.get(position).getState();
        if (state == 1) {//未付款
            holder.mIvZhiFu.setImageResource(R.drawable.weiwancheng);
        } else if (state == 2) {//已付款
            holder.mIvZhiFu.setImageResource(R.drawable.wancheng);
        } else {//取消订单
            holder.mIvZhiFu.setImageResource(R.drawable.wancheng);
        }
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onItemClickListener.onItemClick(position);
            }
        });
    }

    @Override
    public int getItemCount() {
        return dataBean.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {

        private ImageView mIvImg;
        private TextView mTvTitleHome;
        private TextView mTvInTroduce;
        private TextView mTvIntroduction;
        private TextView mTvPriceHome;
        private TextView mTvCless;
        private ImageView mIvZhiFu;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            mIvImg = (ImageView) itemView.findViewById(R.id.iv_img);
            mTvTitleHome = (TextView) itemView.findViewById(R.id.tv_title_home);
            mTvInTroduce = (TextView) itemView.findViewById(R.id.tv_introduce);
            mTvIntroduction = (TextView) itemView.findViewById(R.id.tv_introduction);
            mTvPriceHome = (TextView) itemView.findViewById(R.id.tv_price_home);
            mTvCless = (TextView) itemView.findViewById(R.id.tv_cless);
            mIvZhiFu = (ImageView) itemView.findViewById(R.id.iv_zhifu);
        }
    }
    public onItemClickListener onItemClickListener;

    public void setOnItemClickListener(HomeAdapter4.onItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    public interface onItemClickListener{
        void onItemClick(int position);
    }
}
